﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace XMLProgramReader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty || textBox2.Text == string.Empty || textBox3.Text == string.Empty || comboBox2.Text == string.Empty || comboBox1.Text == string.Empty)
            {
                MessageBox.Show("您还有信息没有录入！");
            }
            else
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(AppDomain.CurrentDomain.BaseDirectory + @"Rules\" + comboBox1.Text + ".xml");
                XmlNode xmlnode = xmldoc.SelectSingleNode("//rule");
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("lenx", textBox1.Text);
                dic.Add("leny", textBox2.Text);
                dic.Add(textBox3.Text, comboBox2.Text);
                jjgzHandler recursion = new jjgzHandler(dic);
                recursion.Recursion(xmlnode);
                double res = recursion.GetPrice();
                MessageBox.Show(res.ToString());
            }
        }
      
        public static ArrayList GetAllFilesByFolder(string folderName, string fileFilter, bool isContainSubFolder)
        {
            ArrayList resArray = new ArrayList();
            string[] files = Directory.GetFiles(folderName, fileFilter);
            for (int i = 0; i < files.Length; i++)
            {
                resArray.Add(files[i]);
            }
            if (isContainSubFolder)
            {
                string[] folders = Directory.GetDirectories(folderName);
                for (int j = 0; j < folders.Length; j++)
                {
                    //遍历所有文件夹
                    ArrayList temp = GetAllFilesByFolder(folders[j], fileFilter, isContainSubFolder);
                    resArray.AddRange(temp);
                }
            }
            return resArray;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
             
            textBox3.Text = "mColor";
            ArrayList arr = GetAllFilesByFolder(AppDomain.CurrentDomain.BaseDirectory + @"Rules", "*.xml", true);
            foreach (string item in arr)
            {
                comboBox1.Items.Add(Path.GetFileNameWithoutExtension(item));
            }
        
        }
    }
}
